package com.xinjian.jianba.examples;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import com.qiniu.util.Auth;

public class download {
    //设置好账号的ACCESS_KEY和SECRET_KEY
	String ACCESS_KEY = "tb1uBM7zB7VBopMs1-VHPnTwz0JsUYh9I194OMB6";
    String SECRET_KEY = "M-zy_OwUebkEmkbDxa6GPA2XMBVTDdHg3GtrkJx9";
    //密钥配置
    Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);
    //构造私有空间的需要生成的下载的链接
    String URL = "jijile.vip";

    public static void main(String args[]) throws UnsupportedEncodingException {
    	String fileName = "my-java.png";
    	String domainOfBucket = "images.jijile.vip";
    	String encodedFileName = URLEncoder.encode(fileName, "utf-8");
    	String finalUrl = String.format("%s/%s", domainOfBucket, encodedFileName);
    	System.out.println(finalUrl);

    	
    }

    public void download() {
        //调用privateDownloadUrl方法生成下载链接,第二个参数可以设置Token的过期时间
        String downloadRUL = auth.privateDownloadUrl(URL, 3600);
        System.out.println(downloadRUL);
    }
}